﻿using System;
using System.Activities;

namespace NMemcached.Client.Activities
{
    /// <summary>
    /// Reads an item from the cache with detail information
    /// </summary>
    public sealed class GetWithDetailActivity : KeyedMemecachedActivity
    {
        /// <summary>
        /// Get or sets the detail value read from the cache
        /// </summary>
        public OutArgument<CacheDetail> Result { get; set; }

        /// <summary>
        /// Initializes a new instance of the GetWithDetailActivity class
        /// </summary>
        public GetWithDetailActivity()
            : base()
        {
        }

        /// <summary>
        /// Performs the execution of the activity
        /// </summary>
        /// <param name="context">The execution context under which the activity executes</param>
        protected override void Execute(CodeActivityContext context)
        {
            base.Execute(context);
            if (String.IsNullOrWhiteSpace(this.CacheKey))
            {
                throw new ArgumentNullException("Key");
            }
            else
            {
                this.Result.Set(context, this.CacheConnection.GetWithDetail(this.CacheKey));
            }
        }
    }
}
